import { GetAliyunToken } from '../../apis/my.js';
export default {
 uploadMed(tempFilePath){
 	let that = this;
 	let url = 'https://hesen-gfn-public.oss-cn-shenzhen.aliyuncs.com';
	return new Promise((resolve, reject) => {

		GetAliyunToken().then( res =>  {
			if(res.code == 0){
				var type = type || 'jpg';
				var type = 'png';
				let date = new Date();
				const random_name = `${date.getFullYear()}/${date.getMonth()+1}/${date.getDate()}/comment/${date.getTime()}.${type}`;
				uni.uploadFile({
					url: url, 
					filePath: tempFilePath,
					name: 'file',
					formData: {
						methods:'post',
						name: tempFilePath,
						key: random_name,
						policy: res.data.policy,
						OSSAccessKeyId: res.data.ossAccessKeyId,
						success_action_status: '200',
						signature:  res.data.signature,
					},
					success(suc){
						let imgAli = url+'/'+random_name;
						resolve(imgAli);
					},
					fail(fail){
						uni.showToast({
							title:fail.errMsg,
							icon:"none"
						})
						reject(fail);
					}
				});
			}else{
				uni.showToast({
					title:res.message,
					icon:"none"
				})
				reject(res);
			}
		})
	})
 },
 
  
}